{extends 'base/site2.html'}
{block name="page_header"}{include file="common/header.html" inline}{/block}
{block name="page_nav"}{include file="common/slide-nav.html" inline}{/block}
{block name="page_styles"}
    <link rel="stylesheet" type="text/css" href="/css/mediation/mediate/index.css" />

{/block}

{block name="page_section"}

    <div class="sessionPage">
        <div class="page-header">
          <div class="left">
            <span class="line"></span>
            <strong class="tit">{if !empty($id)}编辑{else}添加{/if}</strong>
          </div>
        </div>
        <div class="row mr-none" style="width: 95%;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        overflow-x: scroll;">
            <form  class="form-horizontal col-lg-9 pad-no" id="notice-form" >
                <input type="hidden" name="id" value="{if !empty($id)}{$id}{/if}" />
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-4 control-label">状态:</label>
                    <div class="col-sm-2">
                        <select name="status" id="status" class="form-control"   data-valid="notempty">
                            <option value="0" >——请选择——</option>
                            <option {if !empty($list) && $list['status']==1}selected{/if} value="1">有效</option>
                            <option {if !empty($list) && $list['status']==2}selected{/if} value="2">失效</option>
                        </select>
                        <span class="error-tips"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-4 control-label">展示时间段:</label>
                    <div class="col-sm-7">
                        <div class="col-sm-3" style="padding:0;">
                            <input type="date" class="form-control"  id="startTime"  name="startTime" value="{if $list.startTime}{date('Y-m-d',$list.startTime)}{/if}" placeholder="开始时间">
                        </div>
                        <div class="col-sm-1" style="line-height: 30px;padding: 0 15px;">-</div>
                        <div class="col-sm-3" style="padding:0;">
                            <input type="date" class="form-control" id="endTime" name="endTime" value="{if $list.endTime}{date('Y-m-d',$list.endTime)}{/if}" placeholder="结束时间">
                        </div>
                        <span class="error-tips"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-4 control-label">内容:</label>
                    <div class="col-sm-7">
                        <textarea name="content" class="form-control" rows="3" style="width: 70%;margin-bottom: 15px;" id="content">{if !empty($list)}{$list.content}{/if}</textarea>

                        <span class="error-tips"></span>
                    </div>
                </div>


                <div class="form-group">
                    <button type="button" class="btn btn-primary btn-middle col-lg-1 col-md-offset-2 submit" >保存</button>
                    <a href="/notice/index"><button type="button" class="btn btn-default btn-middle col-lg-1 col-md-offset-2">返回</button></a>
                </div>
        </div>
    </div>
{/block}
{block name="page_scripts"}
    <script type="text/javascript" >
        $(".submit").on("click",function(){
            if($("#status").val()==0){
                toastr.error('请选择状态');
                return false;
            }
            console.log($("#content").text());

            if($("#status").text()==0){
                toastr.error('请选择状态');
                return false;
            }
            $.ajax({
                url:"/notice/addAndEdit",
                method:"post",
                data:$("#notice-form").serialize(),
                success:function(res){
                    if(res.code==200){
                        toastr.success("操作成功!");
                        document.location.href="/notice/index";
                    }else{
                        toastr.error(res.message);

                    }
                }
            })
        });
    </script>
{/block}
